See Also

SymmetricCryptoStream Class  | SymmetricCryptoStream Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

buffer
The storage location for the written data.
offset
The zero-based position in the buffer from which to begin writing from.
count
The exact number of bytes to write.
See Also Languages PowerTCP SSL Sockets for .NET

Write(Byte[],Int32,Int32) Method

Dart.PowerTCP.SslSockets Namespace > SymmetricCryptoStream Class > Write Method : Write(Byte[],Int32,Int32) Method

Writes a sequence of bytes to the SymmetricCryptoStream.CoreStream and returns when the operation is complete.

[Visual Basic]
Overloads Overrides Public Sub Write( _    ByVal buffer() As Byte, _    ByVal offset As Integer, _    ByVal count As Integer _ )
[C#]
public override void Write(    byte[] buffer,    int offset,    int count );
[C++]
public: void Write(    byte[]* buffer,    int offset,    int count ) override
[C++/CLI]
public: void Write(    bytearray<buffer>^ buffer,    int offset,    int count ) override

Parameters

buffer
The storage location for the written data.
offset
The zero-based position in the buffer from which to begin writing from.
count
The exact number of bytes to write.

Exceptions

ExceptionDescription
IOExceptionThrown when the Stream is not writeable.
ArgumentNullExceptionThrown when the buffer is null.
ArgumentOutOfRangeExceptionThrown when the offset is less than zero or when count is less than or equal to zero.
ArgumentExceptionThrown when the (offset + count) > buffer.Length.
CryptographicExceptionThrown when the data is unable to be encrypted.

Remarks

This method writes data to the SymmetricCryptoStream.CoreStream, encrypting it with the supplied algorithm and key.

Example

The following example demonstrates encrypting data and writing to a SymmetricCryptoStream on the fly.

[Visual Basic] 

' Create a key and some data.
Dim key As Byte() = System.Text.Encoding.Default.GetBytes("test key")
Dim data As Byte() = System.Text.Encoding.Default.GetBytes("This is the plain text data")

' Create a FileStream to hold the data
Dim f As System.IO.FileStream = New System.IO.FileStream("C:\encrypted\file.txt", System.IO.FileMode.Create)
Dim sc As New SymmetricCryptoStream(AlgorithmType.Rijndael, key, f)

' Always must flush the final block after writing.
sc.FlushFinalBlock()
f.Position=0
f.Close()

' The data is now encrypted and saved to a file. To decrypt, simply initialize a SymmetricCryptoStream
' in the same way as demonstrated above and read from the Filestream, instead of writing to it.

[C#] 


// Create a key and some data.
byte[] key = System.Text.Encoding.Default.GetBytes("test key");
byte[] data = System.Text.Encoding.Default.GetBytes("This is the plain text data");

// Create a FileStream to hold the data
System.IO.FileStream f = new System.IO.FileStream("C:\\encrypted\file.txt", System.IO.FileMode.Create);
SymmetricCryptoStream sc =
new SymmetricCryptoStream(key, f);

// Write to the file. This encrypts the data.
sc.Write(data, 0, data.Length);

// Always must flush the final block after writing.
sc.FlushFinalBlock();
f.Position=0;
f.Close();

// The data is now encrypted and saved to a file. To decrypt, simply initialize a SymmetricCryptoStream
// in the same way as demonstrated above and read from the Filestream, instead of writing to it.
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

SymmetricCryptoStream Class  | SymmetricCryptoStream Members  | Overload List


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.